package com.cn.hnust.controller;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cn.hnust.pojo.Lfdcomment;
import com.cn.hnust.service.ILfdcommentService;
import com.google.gson.Gson;

@Controller
@RequestMapping("/Lfdcomment")
public class LfdcommentController {

	@Resource
	private ILfdcommentService LfdcommentService;

	@RequestMapping("/selectLfdcommentByLid")
	public void selectLfdcommentByLid(HttpServletResponse response, Lfdcomment Lfdcomment, Integer lid)
			throws IOException {
		List<Lfdcomment> list = LfdcommentService.selectLfdcommentByLid(lid);
		Gson gson = new Gson();
		String json = gson.toJson(list);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		response.setContentType("text/json,charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();
		out.write(json);
		out.flush();
	}

	@RequestMapping("/addLfdcomment")
	public void addLfdcomment(HttpServletResponse response, Lfdcomment Lfdcomment, Integer lid,String logo,String name,Integer pinfen,String text,String time)
			throws IOException {
		Lfdcomment.setLid(lid);
		Lfdcomment.setLogo(logo);
		Lfdcomment.setName(name);
		Lfdcomment.setPinfen(pinfen);
		Lfdcomment.setText(text);
		Lfdcomment.setTime(time);
		LfdcommentService.insertSelective(Lfdcomment);
		List<Lfdcomment> list = LfdcommentService.selectLfdcommentByLid(lid);
		Gson gson = new Gson();
		String json = gson.toJson(list);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		response.setContentType("text/json,charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();
		out.write(json);
		out.flush();
	}
}
